﻿import com.mochimedia.ui.*;
import mochimedia.ui.ASUIObject;

/**
 * ...
 * @author Geoff
 */
class Main extends MovieClip {
    
    public var asui:ASUIObject;
    
    public function Main() {
	
		// main container cell
		var b:Cell = new Cell(_root, 400, 300, true, true);
			
		// content cell
		var c:Cell = Cell(b.addChild(new Cell(null, 360, 280, false, false, 0, new Position({ margins: 10 }))));
		
		// tab group for switching to different cells of content
		var tg:TabGroup = new TabGroup(null, ["One", "Two", "Three"], 1);
		c.addChild(tg);

		// HTML field for HTML text
		var d:HTMLField;
		d = HTMLField(c.addChild(new HTMLField(null, "<p>Dude <b>dude</b></p>")));
		d = HTMLField(c.addChild(new HTMLField(null, "Dude")));
		
		Position.defaultMarginBottom = 10;
		
		// button
		var f:BButton;
		f = BButton(c.addChild(new BButton(null, "Apples", -1, 200)));
		f.addEventListener(Component.EVENT_CLICK, this, test);
		
		// combo box
		var cob:ComboBox = new ComboBox(null, "Items", ["Fame", "Fortune", "Love", "Happiness"], 0, "Do it!");
		c.addChild(cob);
		
		// combo box event listener
		cob.addEventListener(Component.EVENT_CLICK, this, onSelect);
		
		// button with icon
		f = BButton(c.addChild(new BButton(null, Create.ICON_CLOSE, -1, 30, 30)));
		
		// html field with link
		var hf:HTMLField = HTMLField(c.addChild(
			new HTMLField(null, 
				'<p>This is an <b>HTML Field</b> with <a href="http:/www.google.com">a link</a>.  Yeah baby!</p>')));
				
		// form field	
		var ff:FormField = new FormField(null, "Enter text...", 200);
		c.addChild(ff);
		
		// radio button group
		var rb:RadioButton = new RadioButton(null, "Hot", "hot", "temperature", false, 100, NaN, new Position( { placement: Position.PLACEMENT_FLOAT } ));
		c.addChild(rb);
		rb.addEventListener(Component.EVENT_CLICK, this, onChoice);
		rb = new RadioButton(null, "Cold", "cold", "temperature", false, 100, NaN, new Position( { placement: Position.PLACEMENT_FLOAT } ));
		c.addChild(rb);
		rb.addEventListener(Component.EVENT_CLICK, onChoice);
		
		c.addChild(new HRule());
		
		// checkbox
		var cb:CheckBox = CheckBox(c.addChild(new CheckBox(null, "Orange")));
		
		// scroll bar for content cell
		var sb:ScrollBar = ScrollBar(b.addChild(new ScrollBar(null)));
		sb.targetCell = c;	
		

        asui = new ASUIObject(null, 450, 200,
            '<div>
                <img class="thumb" src="http://s3.amazonaws.com/twitter_production/profile_images/107885135/geoff2_normal.jpg" width="40" height="40" />
				<div class="meta">
					<h2 class="name">Geoff</h2>
					<hr class="line" />
					<p class="desc">A pretty nice guy.</p>
				</div>
				<div class="controls">
					<input class="control_add" type="button" name="add_item" value="NO WAY" />
				</div>
            </div>
            ',
			'
			.thumb { float: left; width: 40; marginRight: 10; }
			.meta { width:200px;  float: left; marginRight: 10; }
			.name { width:100px; height: 10px; margins: 0; marginBottom: 0; }
			.line { height: 2; marginBottom: 0; }
			.desc { height: 20px; margins: 0; }
			.controls { width: 80px; float: left; textAlign: center; }
			.control_add { position: absolute; backgroundColor: #000000; color: #ffffff;}
			.control_remove { position: absolute; }
			.purchased { fontSize: 16px; color: #666666; }
			');
        
        asui.addEventListener(Component.EVENT_CHANGE, this, onChange);
		asui.addEventListener(Component.EVENT_CLICK, this, onChange);
		
		c.addChild(asui);
        
    }

	public function test (e:Event):Void {
		
		trace(e);
		
	}
	
	public function onSelect (e:Event):Void {
		
		trace("You selected", e.target.value);
		
	}
    
    public function onChange (e:Event):Void {
        trace("change");
        for (var param:String in asui.form) trace(param + "->" + asui.form[param]);
        
    }
	
		
	public function onChoice (e:Event):Void {
		
		trace(RadioButton.groups.temperature.value);			
		
	}
    
    public static function main ():Void {
        
        var app:Main = new Main();
        _global.app = app;
        
    }
    
}